<script>
import { reactive, onMounted, toRefs } from "vue";
export default {
  setup() {
    const list = reactive({
      historylist: null,
    });
    //数据初始化
    onMounted(() => {
      let history = window.localStorage.getItem("history");
      history = JSON.parse(history);
      list.historylist = history;
    });
    //清空
    let del = () => {
      list.historylist = [];
      let history = [];
      history = JSON.stringify(history);
      window.localStorage.setItem("history", history);
    };
    return {
      ...toRefs(list),
      del,
    };
  },
};
</script>
<template>
  <div class="searchView">
    <div class="search">
      <div class="left" @click="$router.go(-1)">
        <i class="iconfont icon-zuojiantou-copy"></i>
      </div>
      <div class="center">最近阅读记录</div>
      <div class="right" @click="del">清空</div>
    </div>
    <div class="items">
      <div class="item" v-for="item in historylist" :key="item.bookTop.bookId">
        <div class="text1"><img :src="item.bookTop.coverImg" alt="" /></div>
        <div class="text2">
          <div class="span1">{{ item.bookTop.bookName }}</div>
          <div class="span2">
            <span>{{ item.bookTop.authorPenName }}</span>
            <span>{{ item.bookTop.authLevel.name }}</span>
          </div>
          <div class="span2">{{ item.bookTop.introduction }}</div>
        </div>
        <div class="text3">阅读</div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.searchView {
  padding: 50px 0;
  .search {
    background-color: #fff;
    z-index: 10;
    position: fixed;
    border-bottom: 2px solid #f7f7f7;
    top: 0;
    left: 0;
    width: 100%;
    box-sizing: border-box;
    align-items: center;
    padding: 8px 15px;
    display: flex;
    justify-content: space-between;
    .center {
      width: 80%;
      position: relative;
      text-align: center;
      font-size: 16px;
      font-weight: 600;
    }
    .right {
      font-size: 12px;
      color: rgb(120, 120, 120);
    }
  }
  .item {
    position: relative;

    width: 100%;
    height: 108px;
    box-sizing: border-box;
    padding: 16px;
    display: flex;
    .text1 {
      width: 55px;
      height: 73px;
      margin-right: 12px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .text2 {
      width: 200px;
      .span1 {
        font-size: 14px;
        font-weight: 550;
        margin-bottom: 8px;
      }
      .span2 {
        width: 100%;
        font-size: 12px;
        color: rgb(172, 172, 172);
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        margin-bottom: 8px;
        span {
          margin-right: 5px;
        }
      }
    }
    .text3 {
      position: absolute;
      top: 36px;
      right: 20px;
      width: 54px;
      height: 22px;
      border: 1px solid rgb(172, 172, 172);
      line-height: 22px;
      text-align: center;
      font-size: 13px;
      border-radius: 5px;
    }
  }
}
</style>